﻿#include "pch.h"
#include "OpenGLContext.h"

#include "core/Macro.h"
#include "core/log/LogSystem.h"

namespace Engine
{
	OpenGLContext::OpenGLContext(GLFWwindow* windowHandle) : windowHandle(windowHandle)
	{
		ENGINE_ASSERT(windowHandle, "创建窗口失败！")
	}

	void OpenGLContext::Init()
	{
		glfwMakeContextCurrent(windowHandle);

		const int status = gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress));
		ENGINE_ASSERT(status, "初始化 Glad 失败！");

		ENGINE_TRACE("GPU 供应商: {0}", (char*)glGetString(GL_VENDOR));
		ENGINE_TRACE("GPU 型号: {0}", (char*)glGetString(GL_RENDERER));
		ENGINE_TRACE("GPU 驱动版本: {0}", (char*)glGetString(GL_VERSION));
	}

	void OpenGLContext::SwapBuffers()
	{
		glfwSwapBuffers(windowHandle);
	}
}
